package o;

import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.text.style.StyleSpan;
import android.text.style.TypefaceSpan;
import android.text.style.UnderlineSpan;
import com.google.android.exoplayer2.text.Cue;
import com.google.android.exoplayer2.text.SubtitleDecoderException;
import java.nio.charset.Charset;
import java.util.List;

public final class akk extends ajh {
    private static final int ˎ = anr.ᐝ("tbox");
    private static final int ॱ = anr.ᐝ("styl");
    private int ʻ;
    private int ʼ;
    private String ʽ;
    private boolean ˊ;
    private int ˋ;
    private final anc ˏ = new anc();
    private float ᐝ;

    public akk(List<byte[]> list) {
        super("Tx3gDecoder");
        ॱ(list);
    }

    private void ॱ(List<byte[]> list) {
        if (list != null && list.size() == 1 && (((byte[]) list.get(0)).length == 48 || ((byte[]) list.get(0)).length == 53)) {
            boolean z;
            byte[] bArr = (byte[]) list.get(0);
            this.ˋ = bArr[24];
            this.ʼ = ((((bArr[26] & 255) << 24) | ((bArr[27] & 255) << 16)) | ((bArr[28] & 255) << 8)) | (bArr[29] & 255);
            this.ʽ = "Serif".equals(anr.ˊ(bArr, 43, bArr.length + -43)) ? "serif" : "sans-serif";
            this.ʻ = bArr[25] * 20;
            if ((bArr[0] & 32) != 0) {
                z = true;
            } else {
                z = false;
            }
            this.ˊ = z;
            if (this.ˊ) {
                this.ᐝ = ((float) ((bArr[11] & 255) | ((bArr[10] & 255) << 8))) / ((float) this.ʻ);
                this.ᐝ = anr.ˋ(this.ᐝ, 0.0f, 0.95f);
                return;
            }
            this.ᐝ = 0.85f;
            return;
        }
        this.ˋ = 0;
        this.ʼ = -1;
        this.ʽ = "sans-serif";
        this.ˊ = false;
        this.ᐝ = 0.85f;
    }

    protected aji ˎ(byte[] bArr, int i, boolean z) throws SubtitleDecoderException {
        this.ˏ.ॱ(bArr, i);
        CharSequence ˊ = ˊ(this.ˏ);
        if (ˊ.isEmpty()) {
            return akm.ॱ;
        }
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(ˊ);
        ॱ(spannableStringBuilder, this.ˋ, 0, 0, spannableStringBuilder.length(), 16711680);
        ˏ(spannableStringBuilder, this.ʼ, -1, 0, spannableStringBuilder.length(), 16711680);
        ˊ(spannableStringBuilder, this.ʽ, "sans-serif", 0, spannableStringBuilder.length(), 16711680);
        float f = this.ᐝ;
        while (this.ˏ.ˊ() >= 8) {
            int ˋ = this.ˏ.ˋ();
            int ॱᐝ = this.ˏ.ॱᐝ();
            int ॱᐝ2 = this.ˏ.ॱᐝ();
            if (ॱᐝ2 == ॱ) {
                ˋ(this.ˏ.ˊ() >= 2);
                int ॱॱ = this.ˏ.ॱॱ();
                for (ॱᐝ2 = 0; ॱᐝ2 < ॱॱ; ॱᐝ2++) {
                    ॱ(this.ˏ, spannableStringBuilder);
                }
            } else if (ॱᐝ2 == ˎ && this.ˊ) {
                ˋ(this.ˏ.ˊ() >= 2);
                f = anr.ˋ(((float) this.ˏ.ॱॱ()) / ((float) this.ʻ), 0.0f, 0.95f);
            }
            this.ˏ.ˋ(ˋ + ॱᐝ);
        }
        return new akm(new Cue(spannableStringBuilder, null, f, 0, 0, Float.MIN_VALUE, Integer.MIN_VALUE, Float.MIN_VALUE));
    }

    private static String ˊ(anc o_anc) throws SubtitleDecoderException {
        ˋ(o_anc.ˊ() >= 2);
        int ॱॱ = o_anc.ॱॱ();
        if (ॱॱ == 0) {
            return "";
        }
        if (o_anc.ˊ() >= 2) {
            char ᐝ = o_anc.ᐝ();
            if (ᐝ == '﻿' || ᐝ == '￾') {
                return o_anc.ˊ(ॱॱ, Charset.forName("UTF-16"));
            }
        }
        return o_anc.ˊ(ॱॱ, Charset.forName("UTF-8"));
    }

    private void ॱ(anc o_anc, SpannableStringBuilder spannableStringBuilder) throws SubtitleDecoderException {
        ˋ(o_anc.ˊ() >= 12);
        int ॱॱ = o_anc.ॱॱ();
        int ॱॱ2 = o_anc.ॱॱ();
        o_anc.ˎ(2);
        int ʽ = o_anc.ʽ();
        o_anc.ˎ(1);
        int ॱᐝ = o_anc.ॱᐝ();
        ॱ(spannableStringBuilder, ʽ, this.ˋ, ॱॱ, ॱॱ2, 0);
        ˏ(spannableStringBuilder, ॱᐝ, this.ʼ, ॱॱ, ॱॱ2, 0);
    }

    private static void ॱ(SpannableStringBuilder spannableStringBuilder, int i, int i2, int i3, int i4, int i5) {
        int i6 = 1;
        if (i != i2) {
            int i7;
            int i8 = i5 | 33;
            int i9 = (i & 1) != 0 ? 1 : 0;
            if ((i & 2) != 0) {
                i7 = 1;
            } else {
                i7 = 0;
            }
            if (i9 != 0) {
                if (i7 != 0) {
                    spannableStringBuilder.setSpan(new StyleSpan(3), i3, i4, i8);
                } else {
                    spannableStringBuilder.setSpan(new StyleSpan(1), i3, i4, i8);
                }
            } else if (i7 != 0) {
                spannableStringBuilder.setSpan(new StyleSpan(2), i3, i4, i8);
            }
            if ((i & 4) == 0) {
                i6 = 0;
            }
            if (i6 != 0) {
                spannableStringBuilder.setSpan(new UnderlineSpan(), i3, i4, i8);
            }
            if (i6 == 0 && i9 == 0 && i7 == 0) {
                spannableStringBuilder.setSpan(new StyleSpan(0), i3, i4, i8);
            }
        }
    }

    private static void ˏ(SpannableStringBuilder spannableStringBuilder, int i, int i2, int i3, int i4, int i5) {
        if (i != i2) {
            spannableStringBuilder.setSpan(new ForegroundColorSpan(((i & 255) << 24) | (i >>> 8)), i3, i4, i5 | 33);
        }
    }

    private static void ˊ(SpannableStringBuilder spannableStringBuilder, String str, String str2, int i, int i2, int i3) {
        if (str != str2) {
            spannableStringBuilder.setSpan(new TypefaceSpan(str), i, i2, i3 | 33);
        }
    }

    private static void ˋ(boolean z) throws SubtitleDecoderException {
        if (!z) {
            throw new SubtitleDecoderException("Unexpected subtitle format.");
        }
    }
}
